#include <bits/stdc++.h>
using namespace std;
long long T,n,m,L,V,d[100005],v[100005],a[100005],p[100005],maxp=-99999;
long long c=0,b;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
            if(p[i]>maxp) maxp=p[i];
        }
        for(int i=1;i<=n;i++){
            if(d[i]<=maxp&&v[i]>V)c++;
        }
        if(c==0){
            cout<<c<<' '<<m<<endl;
        }else{
            cout<<c<<' '<<m-1<<endl;
        }
        maxp = -99999;c=0;b=0;
    }
    return 0;
}
